package com.budwk.app.sqfwV2.generator.dayingRoadPdf.rw;

import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwV2.dto.dayingRoad.DaYingLuRedRecordPdfDTO;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.deepoove.poi.data.PictureRenderData;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * PDF婚事办理酒席备案表.docx
 */
public class RedHandleCateringRecordsPdfGenerator extends BasePdfGenerator {

    @Override
    protected boolean pdfCreateConditionCheck(PdfGenerateParam pdfGenerateParam) {
        return true;
    }

    @Override
    protected void customerPopularPdfParam(Map<String, Object> paramMap, PdfGenerateParam pdfGenerateParam) {
        DaYingLuRedRecordPdfDTO redRecordPdfDTO = (DaYingLuRedRecordPdfDTO) pdfGenerateParam.getAbstractCustomerPdfCreateField();
        // 政治面貌
        Boolean isPartyMemberRecordKeeper = redRecordPdfDTO.getIsPartyMemberRecordKeeper();
        paramMap.put("isPartyMemberRecordKeeper", isPartyMemberRecordKeeper ? "党员" : "其他");
        Boolean isPartyMemberSpouse = redRecordPdfDTO.getIsPartyMemberSpouse();
        paramMap.put("isPartyMemberSpouse", isPartyMemberSpouse ? "党员" : "其他");
        // 有无低俗婚闹
        Boolean weddingPranks = redRecordPdfDTO.getWeddingPranks();
        paramMap.put("weddingPranks", weddingPranks ? "有" : "无");

        // 是否办酒
        if ("未办酒".equals(redRecordPdfDTO.getBanquetForm())) {
            paramMap.put("banquetCost", "-");
            paramMap.put("banquetTime", "-");
            paramMap.put("banquetLocation", "-");
            paramMap.put("isJointWedding", "-");
            paramMap.put("banquetTableCount", "-");
        } else {
            // 桌餐标准
            Long banquetCost = redRecordPdfDTO.getBanquetCost();
            // 分转元
            paramMap.put("banquetCost", BigDecimal.valueOf(banquetCost).divide(new BigDecimal(100)));
        }

        // 图片处理
        Object signature = pdfGenerateParam.getCustomerParamMap().get("signature");
        List<String> signatureList = Arrays.asList(signature == null ? "" : signature.toString());
        String signatureName = "signature";
        List<Map<String, PictureRenderData>> signatures = CommonFormOfficeUtils.addWordPicture(signatureList, signatureName, 1.0F);
        paramMap.put(signatureName + "s", signatures);
        if (signature != null && StringUtils.isNotBlank(signature.toString())) {
            paramMap.put("createUserName", "");
        }
    }

    @Override
    public String getTemplatePath(PdfGenerateParam pdfGenerateParam) {
        return "daYingLu/red/handleCateringRecords.docx";
    }
}
